package cn.com.headfree.server.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.gta.edu.sdk.base.dao.impl.BaseDaoImpl;
import com.gta.edu.sdk.common.dto.Page;
import com.gta.edu.sdk.util.StringUtil;

import cn.com.headfree.server.dao.IServerItemDao;
import cn.com.headfree.server.dto.ZuulServerItemDto;
import cn.com.headfree.server.entity.TZuulServerItem;


@Repository("serverItemDao")
public class ServerItemDaoImpl extends BaseDaoImpl<TZuulServerItem> implements IServerItemDao {

	@Override
	public void findAsPage(String serverId, Integer isEable, Page<ZuulServerItemDto> page) {
		List<Object> params = new ArrayList<Object>(2);
		StringBuilder sql = new StringBuilder("select t.*,s.name as server_name from t_zuul_server_item t,t_zuul_server_info s where t.server_id=s.id ");
		if (!StringUtil.isNullOrEmpty(serverId)) {
			sql.append(" and t.server_id=?");
			params.add(serverId);
		}
		if (isEable != null) {
			sql.append(" and t.is_enable=?");
			params.add(isEable);
		}
		sql.append(" order by t.update_time asc");
		this.findPageBySql(ZuulServerItemDto.class, sql.toString(), page, params.toArray());
	}

	@Override
	public List<TZuulServerItem> findAll() {
		return this.findAllBySQL(TZuulServerItem.class, "select * from t_zuul_server_item t where t.is_enable=1 ", null, false, null);
	}

}
